package com.github.shiqiyue.app.modules.dbms.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.shiqiyue.app.api.sapi.controller.dbms.req.DatabaseHistoryPageReq;
import com.github.shiqiyue.app.modules.dbms.entity.DatabaseHistory;
import com.github.shiqiyue.app.modules.dbms.mapper.DatabaseHistoryMapper;
import com.github.shiqiyue.app.modules.dbms.service.IDatabaseHistoryService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 数据库-历史记录 服务实现类
 * </p>
 *
 * @author wenyao.wu
 * @since 2019-08-06
 */
@Service
public class DatabaseHistoryServiceImpl extends ServiceImpl<DatabaseHistoryMapper, DatabaseHistory> implements IDatabaseHistoryService {


    @Override
    public void addHistory(Long databaseId, String remark, DatabaseHistory.Type type, Long operatorId) {
        DatabaseHistory databaseHistory = new DatabaseHistory();
        databaseHistory.setDatabaseId(databaseId);
        databaseHistory.setRemark(remark);
        databaseHistory.setType(type);
        databaseHistory.setUserId(operatorId);
        baseMapper.insert(databaseHistory);
    }

    @Override
    public IPage<DatabaseHistory> page(DatabaseHistoryPageReq databaseHistoryPageReq) {
        return baseMapper.page(new Page<DatabaseHistory>(databaseHistoryPageReq.getCurrent(), databaseHistoryPageReq.getSize()),
                databaseHistoryPageReq);

    }
}
